using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class PlayerManager : MonoBehaviour,ISaveManager
{
    static public PlayerManager instance;
    public Player player;

    private int currency;  // 钱 
    public delegate void OnCurrencyChangedDelegate(int value);
    public OnCurrencyChangedDelegate OnCurrencyChanged;

    public int Currency
    { 
        get { return currency; }
        set {
            if (OnCurrencyChanged != null)
            { 
                OnCurrencyChanged(value);
            }
            currency = value; 
        }
    }

    private void Awake()
    {
        if (instance != null)
        {
            Destroy(instance.gameObject);
        }
        else
        {
            instance = this;
        }
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.RightControl)) {
            Currency += 100;
        }
        if (player.transform.position.y < -5)
        {
            player.Die();
        }
    }

    public void LoadGame(GameData gameData)
    {
        this.Currency = gameData.currency;
    }

    public void SaveGame(ref GameData gameData)
    {
        gameData.currency = this.Currency;
    }
}
